package com.xmzs.web.controller;


import com.xmzs.common.chat.service.SseService;
import com.xmzs.common.chat.domain.request.ChatRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;

import java.util.Map;

/**
 * 描述：
 *
 * @author https:www.unfbx.com
 * @date 2023-03-01
 */
@Controller
@Slf4j
public class ChatController {

    private final SseService sseService;

    public ChatController(SseService sseService) {
        this.sseService = sseService;
    }

    /**
     * 聊天接口
     *
     */
    @CrossOrigin
    @PostMapping("/chat")
    @ResponseBody
    public ResponseBodyEmitter sseChat(@RequestBody @Valid ChatRequest chatRequest, HttpServletResponse response) {
        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        return sseService.sseChat(chatRequest);
    }

}
